package cn.persistenceCollection.demos;

import cn.persistenceCollection.JdkSerializer;
import cn.persistenceCollection.PersistenceContext;
import com.easy.server.persistenceCollection.FileMapperType;

import java.util.List;
import java.util.Set;

public class k100mDemo {
    public static void main(String[] args) {
        PersistenceContext persistenceContext = new PersistenceContext(".");

        persistenceContext.setDefaultFileMapperType(FileMapperType.MergedMemoryMapMapper);
        persistenceContext.setFlushPerOption(false);
        persistenceContext.setFlushIntervalMills(1000);
        persistenceContext.setMapOrSetValueRedundancyBytesRatio(-1);

        long start = System.currentTimeMillis();
        Set<String> list = persistenceContext.openSet("set777", new JdkSerializer<>(String.class), 100_000_000);
        String name = "艺龙酒店艺龙酒店艺龙酒店艺龙酒店艺龙酒店";

//        int count = 0;
//        for (int i = 0; i <1_000_000; i++) {
//            if (list.contains(name+i)) {
//                count++;
//                if(count%100_000==0){
//                    System.out.println(System.currentTimeMillis()-start+" mills at :"+i+" -> "+count);
//                }
//            }
////            System.out.println(System.currentTimeMillis()-start+" mills at :"+i);
//        }

        for (int i = 0; i < 100_000_000; i++) {
            list.add(name+i);
            if(i%10_000_000==0){
                System.out.println(System.currentTimeMillis()-start+" mills at :"+i);
                System.out.println(list.size());
            }
        }

        persistenceContext.close();
        System.out.println(6);
    }
}
